package com.freesky.web.manager.remote;

import com.freesky.common.pojo.KindEditorResult;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.manager.remote.fallback.ImageRemoteFallback;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(name = "emall-provider-image", fallback = ImageRemoteFallback.class,configuration = ImageRemote.FeignMultipartSupportConfig.class)
public interface ImageRemote {
    @RequestMapping(value ="/image/imageUpload", method = RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    JSONResponse uploadFile(@RequestPart("file") MultipartFile files);

    @PostMapping(value = "/kindeditor/imageUpload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    KindEditorResult kindEditor(@RequestPart("imgFile")MultipartFile files);

    class FeignMultipartSupportConfig {

        @Bean
        public Encoder multipartFormEncoder() {
            return new SpringFormEncoder();
        }

        @Bean
        public feign.Logger.Level multipartLoggerLevel() {
            return feign.Logger.Level.FULL;
        }
    }

}
